<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/extension_registry.html">
<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('tberSimpleNamedRegistration', function() {
    function DummyEvent() {
    }
    DummyEvent.prototype = {
    };

    function DummyEventSubclass() {
    }
    DummyEventSubclass.prototype = {
      __proto__: DummyEvent.prototype
    };

    const options = new tr.b.ExtensionRegistryOptions(
        tr.b.TYPE_BASED_REGISTRY_MODE);
    options.mandatoryBaseClass = DummyEvent;
    options.defaultConstructor = DummyEvent;
    tr.b.decorateExtensionRegistry(
        DummyEvent, options);

    DummyEvent.register(DummyEventSubclass, {typeName: 'dummy-name'});
    assert.strictEqual(DummyEvent, DummyEvent.getConstructor('cat', 'name'));
    assert.strictEqual(
        DummyEvent.getConstructor('dummy', 'dummy-name'), DummyEventSubclass);
    DummyEvent.unregister(DummyEventSubclass);
    assert.strictEqual(
        DummyEvent, DummyEvent.getConstructor('dummy', 'dummy-name'));
  });

  test('tberSimpleCategoryRegistration', function() {
    function DummyEvent() {
    }
    DummyEvent.prototype = {
    };

    function DummyEventSubclass() {
    }
    DummyEventSubclass.prototype = {
      __proto__: DummyEvent.prototype
    };

    const options = new tr.b.ExtensionRegistryOptions(
        tr.b.TYPE_BASED_REGISTRY_MODE);
    options.mandatoryBaseClass = DummyEvent;
    options.defaultConstructor = DummyEvent;
    tr.b.decorateExtensionRegistry(
        DummyEvent, options);

    DummyEvent.register(
        DummyEventSubclass,
        {categoryParts: ['dummy']
        });
    assert.strictEqual(DummyEvent, DummyEvent.getConstructor('cat', 'name'));
    assert.strictEqual(DummyEvent.getConstructor('dummy', 'dummy-name'),
        DummyEventSubclass);
    DummyEvent.unregister(DummyEventSubclass);
    assert.strictEqual(
        DummyEvent, DummyEvent.getConstructor('dummy', 'dummy-name'));
  });

  test('tberSimpleCompoundCategory', function() {
    function DummyEvent() {
    }
    DummyEvent.prototype = {
    };

    function DummyEventSubclass() {
    }
    DummyEventSubclass.prototype = {
      __proto__: DummyEvent.prototype
    };

    const options = new tr.b.ExtensionRegistryOptions(
        tr.b.TYPE_BASED_REGISTRY_MODE);
    options.mandatoryBaseClass = DummyEvent;
    options.defaultConstructor = DummyEvent;
    tr.b.decorateExtensionRegistry(
        DummyEvent, options);

    DummyEvent.register(
        DummyEventSubclass,
        {
          categoryParts: ['dummy']
        });
    assert.strictEqual(DummyEvent, DummyEvent.getConstructor('cat', 'name'));
    assert.strictEqual(DummyEventSubclass,
        DummyEvent.getConstructor('dummy,something-else',
            'dummy-name'));
  });

  test('tberDefaultType', function() {
    function DummyEvent() {
    }
    DummyEvent.prototype = {
    };

    function DummyEventSubclass() {
    }
    DummyEventSubclass.prototype = {
      __proto__: DummyEvent.prototype
    };

    const options = new tr.b.ExtensionRegistryOptions(
        tr.b.TYPE_BASED_REGISTRY_MODE);
    options.mandatoryBaseClass = DummyEvent;
    options.defaultConstructor = DummyEvent;
    tr.b.decorateExtensionRegistry(
        DummyEvent, options);

    DummyEvent.register(
        DummyEventSubclass,
        {
          categoryParts: ['dummy']
        });
    assert.strictEqual(DummyEvent, DummyEvent.getConstructor('cat', 'name'));
    assert.strictEqual(DummyEventSubclass,
        DummyEvent.getConstructor('dummy,something-else',
            'dummy-name'));
  });
});
</script>
